package com.map;

import java.util.Enumeration;
import java.util.Properties;
import java.util.Set;

public class PropertiesTest {
	public static void main(String[] args) {
		Properties ps = new Properties();// Map<String string>
		// 设置属性
		ps.setProperty("admin.acount", "name1");
		ps.setProperty("admin.acount", "name2");
		// ps.put(key, value);不建议使用
		System.out.println(ps);
		// 获取属性
		String v = ps.getProperty("name1");
		System.out.println("name1=" + v);
		System.out.println("ps.getProperty(name2)" + ps.getProperty("name2"));
		System.out.println("ps.getProperty(name2, \"默认值\")" + ps.getProperty("name2", "默认值"));
		{
			// 遍历属性
			Enumeration<?> names = ps.propertyNames();
			while (names.hasMoreElements()) {
				String name = (String) names.nextElement();
				System.out.println(name + "=" + ps.getProperty(name));
			}
		}
		{
			System.out.println("---------遍历属性");
			Set<String> names = ps.stringPropertyNames();
			for(String name : names) {
				System.out.println(name + "=" + ps.getProperty(name));
			}
		}
	}
}
